home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 25 / AMIGAplus Sonderheft 25 (2000)(Falke)(DE)(Track 1 of 4)[!].iso / Updates / HD-Installer / jst_dev / sources / src / DiskTools / psywfiles.asm < prev    next >
Assembly Source File  |  2000-04-12  |  3KB  |  195 lines

  1. ; *** Psygnosis disk utilities V1.1
  2. ; *** Written by Jean-François Fabre
  3.  
  4.     include    "libs.i"
  5.  
  6.     XREF    _SysBase
  7.  
  8.     XDEF    _WriteFiles
  9.     XDEF    @WriteFiles
  10.  
  11.  
  12. ; *** create several files from the disk image
  13. ; *** very intricate routine, sorry
  14.  
  15. ; in: A0/stack: diskfile buffer
  16. ; out D0: error flag (0=OK)
  17.  
  18. _WriteFiles:
  19.     move.l    4(A7),A0
  20.  
  21. @WriteFiles:
  22.     movem.l    D1-A6,-(sp)
  23.     move.l    A0,DiskBuffer
  24.  
  25.     lea    dosname,A1
  26.     moveq    #0,D0
  27.     move.l    _SysBase,A6
  28.     JSRLIB    OpenLibrary
  29.     move.l    D0,dosbase
  30.     beq    WF_UN_Error
  31.  
  32.     move.l    DiskBuffer,A0
  33.     lea    $10(A0),A1    ; for directory buffer, variable by $10
  34.     lea    $C00(A0),A2    ; for directory block list, constant
  35.     moveq.l    #1,D6        ; the file counter, starts at 1
  36.  
  37.     ; *** LOOP ON THE FILES
  38. wloop$
  39.     cmp.b    #$FF,(A1)    ; no name -> no more files
  40.     beq    WF_OK
  41.  
  42.     ; ** for each file, allocate a buffer to join the
  43.     ; ** different file parts
  44.  
  45.     move.l    $C(A1),D0    ; file length
  46.     add.l    #$400,D0    ; to be able not to overflow buffer
  47.     move.l    D0,blocksize    ; store the size
  48.  
  49.     movem.l    D1-A6,-(sp)
  50.     move.l    blocksize,D0
  51.     move.l    #MEMF_CLEAR,D1
  52.     move.l    _SysBase,A6
  53.     JSRLIB    AllocMem
  54.     movem.l    (sp)+,D1-A6
  55.     move.l    D0,blockbuffer
  56.     beq    WF_AM_Error
  57.     
  58.     move.l    blockbuffer,A4    ; A4: current pointer on the file buffer
  59.  
  60.     ; ** search the block bitmap for relevant blocks
  61.  
  62.     moveq.l    #0,D3    ; block counter
  63. sloop$
  64.     move.b    (A2,D3.W),D4
  65.  
  66.     cmp.w    #$3FF,D3
  67.     bcs    notend$
  68.  
  69.     cmp.b    #$FF,D4
  70.     beq    writefile$    ; end of block info -> write file please
  71.     bra    WF_DC_Error    ; ripped disk corrupt, directory error
  72.  
  73. notend$
  74.     cmp.b    D6,D4        ; block matches our file??
  75.     beq    matchblock$
  76. nextblock$
  77.     addq.l    #1,D3        ; next offset
  78.     bra    sloop$
  79.  
  80.     ; *** calculate the real offset and copy the block in the buffer
  81. matchblock$
  82.     move.l    D3,D4        ; copy position
  83.     lsl.l    #8,D4        ; *256
  84.     lsl.l    #2,D4        ; *4   -> *$400
  85.     sub.l    #$3000,D4    ; we started from physical track 2
  86.     move.l    DiskBuffer,A3
  87.     add.l    D4,A3
  88.  
  89.     ; ** copies a block in the file buffer
  90.  
  91.     move.w    #$FF,D5
  92. bcopy$
  93.     move.l    (A3)+,(A4)+
  94.     dbf    D5,bcopy$
  95.  
  96.     bra    nextblock$
  97.  
  98. writefile$
  99.     ; *** open a new file
  100.  
  101.     move.l    A1,D1        ; pointer on the file name to create
  102.     move.l    #MODE_NEWFILE,D2
  103.     move.l    dosbase,A6
  104.     movem.l    D1-A6,-(sp)
  105.     JSRLIB    Open        ; open a new file
  106.     movem.l    (sp)+,D1-A6
  107.     tst.l    D0
  108.     beq    WF_CF_Error
  109.  
  110.     ; *** write the data to the file
  111.  
  112.     move.l    D0,FHandle
  113.     move.l    D0,D1
  114.     move.l    blockbuffer,D2
  115.     move.l    $C(A1),D3    ; file length
  116.     move.l    dosbase,A6
  117.     movem.l    D1-A6,-(sp)
  118.     JSRLIB    Write
  119.     movem.l    (sp)+,D1-A6
  120.  
  121.     ; *** close the file
  122.  
  123.     move.l    FHandle,D1
  124.     move.l    dosbase,A6
  125.     movem.l    D1-A6,-(sp)
  126.     JSRLIB    Close
  127.     movem.l    (sp)+,D1-A6
  128.     clr.l    FHandle
  129.  
  130.     bsr    FreeBlockBuffer
  131.  
  132.     ; *** increase the pointer
  133.     ; *** and the file counter
  134. nextfile$
  135.     lea    $10(A1),A1
  136.     addq.l    #1,D6
  137.     bra    wloop$
  138.     
  139. WF_OK:
  140.     moveq.l    #0,D0
  141. WF_Exit:
  142.     move.l    dosbase,D1
  143.     beq    fuck$
  144.     move.l    D1,A1
  145.     move.l    _SysBase,A6
  146.     JSRLIB    CloseLibrary
  147.     move.l    #0,dosbase
  148. fuck$
  149.     bsr    FreeBlockBuffer
  150.     movem.l    (sp)+,D1-A6
  151.     rts
  152.  
  153.  
  154. WF_CF_Error:
  155.     moveq.l    #-1,D0
  156.     bra    WF_Exit
  157.  
  158. WF_UN_Error:
  159.     moveq.l    #-2,D0
  160.     bra    WF_Exit
  161.  
  162. WF_DC_Error:
  163.     moveq.l    #-3,D0
  164.     bra    WF_Exit
  165.  
  166. WF_AM_Error:
  167.     moveq.l    #-5,D0
  168.     bra    WF_Exit
  169.     
  170. FreeBlockBuffer:
  171.     STORE_REGS
  172.     move.l    blockbuffer,D1
  173.     beq    skip$
  174.     move.l    D1,A1
  175.     move.l    blocksize,D0
  176.     move.l    _SysBase,A6
  177.     JSRLIB    FreeMem
  178.     clr.l    blockbuffer
  179. skip$
  180.     RESTORE_REGS
  181.     rts
  182.  
  183. blocksize:
  184.     dc.l    0
  185. blockbuffer:
  186.     dc.l    0
  187. DiskBuffer:
  188.     dc.l    0
  189. FHandle:
  190.     dc.l    0
  191. dosbase:
  192.     dc.l    0
  193. dosname:
  194.     dc.b    "dos.library",0
  195.